package com.aternity.geolocations.byip;

import com.maxmind.geoip.*;
import java.io.IOException;

class CountryLookup {
    public static void main(String[] args) {
        try {
            String sep = System.getProperty("file.separator");

            // Uncomment for windows
            // String dir = System.getProperty("user.dir");

            // Uncomment for Linux
            String dir = "/usr/local/share/GeoIP";

            String dbfile = "C:/temp/GeoIP.dat";
            // You should only call LookupService once, especially if you use
            // GEOIP_MEMORY_CACHE mode, since the LookupService constructor takes up
            // resources to load the GeoIP.dat file into memory
            //LookupService cl = new LookupService(dbfile,LookupService.GEOIP_STANDARD);
            LookupService cl = new LookupService("C:/temp/GeoIP.dat",LookupService.GEOIP_MEMORY_CACHE);


            LookupService cl2 = new LookupService("C:/temp/GeoLiteCity.dat",
                    LookupService.GEOIP_MEMORY_CACHE );


//            System.out.println(cl.getCountry("151.38.39.114").getCode());
//            System.out.println(cl.getCountry("151.38.39.114").getName());
//            System.out.println(cl.getCountry("80.179.241.21").getCode());
//            System.out.println(cl.getCountry("80.179.241.21").getName());
//            System.out.println(cl.getCountry("12.25.205.51").getName());
//            System.out.println(cl.getCountry("64.81.104.131").getName());
//            System.out.println(cl.getCountry("200.21.225.82").getName());

            cl.close();



            Location l2 = cl2.getLocation("46.120.208.208");
            System.out.println("countryCode: " + l2.countryCode +
                    "\n countryName: " + l2.countryName +
                    "\n region: " + l2.region +
                    "\n regionName: " + regionName.regionNameByCode(l2.countryCode, l2.region) +
                    "\n city: " + l2.city +
                    "\n postalCode: " + l2.postalCode +
                    "\n latitude: " + l2.latitude +
                    "\n longitude: " + l2.longitude +
                    "\n metro code: " + l2.metro_code +
                    "\n area code: " + l2.area_code +
                    "\n timezone: " + timeZone.timeZoneByCountryAndRegion(l2.countryCode, l2.region));
        }
        catch (IOException e) {
            System.out.println("IO Exception");
        }
    }
}
